namespace YXShop.ExcelLite
{
    using System;
    using System.Drawing;

    public sealed class CellBorder
    {
        private readonly IndividualBorder borderId;
        private readonly int borderIndex;
        private readonly CellStyle parent;

        internal CellBorder(CellStyle parent, IndividualBorder borderId)
        {
            this.parent = parent;
            this.borderId = borderId;
            this.borderIndex = IndexFromIndividualBorder(borderId);
        }

        internal static int IndexFromIndividualBorder(IndividualBorder individualBorder)
        {
            int num = (int) individualBorder;
            if (num == 5)
            {
                num = 4;
            }
            return num;
        }

        internal static MultipleBorders MultipleFromIndividualBorder(IndividualBorder individualBorder)
        {
            return (MultipleBorders) (((int) 1) << individualBorder);
        }

        public void SetBorder(Color lineColor, YXShop.ExcelLite.LineStyle lineStyle)
        {
            this.LineColor = lineColor;
            this.LineStyle = lineStyle;
        }

        private void SetUsedIfNotDefault()
        {
            CellStyleData element = this.parent.Element;
            if ((element.BorderStyle[this.borderIndex] != YXShop.ExcelLite.LineStyle.None) || (element.BorderColor[this.borderIndex].ToArgb() != Color.Black.ToArgb()))
            {
                element.BordersUsed |= MultipleFromIndividualBorder(this.borderId);
            }
        }

        public Color LineColor
        {
            get
            {
                return this.parent.Element.BorderColor[this.borderIndex];
            }
            set
            {
                this.parent.BeforeChange();
                this.parent.Element.BorderColor[this.borderIndex] = value;
                this.SetUsedIfNotDefault();
            }
        }

        public YXShop.ExcelLite.LineStyle LineStyle
        {
            get
            {
                return this.parent.Element.BorderStyle[this.borderIndex];
            }
            set
            {
                this.parent.BeforeChange();
                this.parent.Element.BorderStyle[this.borderIndex] = value;
                this.SetUsedIfNotDefault();
            }
        }
    }
}

